#include <string.h>
#include "xml/morexml.h"

int xmlIsA(xmlNodePtr node,const char* name)
    {
    if(node==NULL || name==NULL || node->type != XML_ELEMENT_NODE )
           return 0;
    return (xmlStrcmp( node->name, BAD_CAST name)==0?1:0);
    }

xmlNodePtr xmlFindFirst(xmlNodePtr root,const char* name)
    {
    xmlNodePtr child;
    if(root==NULL || name==NULL) return 0;
    child =root->children;
    while(child!=NULL)
        {
        if(xmlIsA(child,name)) return child;
        child=child->next;
        }
    return NULL;
    }

xmlChar* xmlFindContent(xmlNodePtr root,const char* name)
    {
    xmlNodePtr child= xmlFindFirst(root,name);
    if(child==NULL) return NULL;
    if(child->children==NULL) return NULL;
    return xmlNodeGetContent(child);
    }

int xmlHasAttribute(xmlNodePtr node,const char* name,const char* value)
    {
    int result=0;
    xmlChar* s;
    if(node==NULL || name==NULL || value==NULL) return 0;
    s = xmlGetProp(node,BAD_CAST name);
    if(s==NULL) return 0;
    if(xmlStrcmp(s,BAD_CAST value)==0)
        {
        result=1;
        }
    xmlFree(s);
    return result;
    }

int xmlHasContent(xmlNodePtr node,const char* value)
    {
    int result=0;
    xmlChar* s;
    if(node==NULL || value==NULL) return 0;
    s = xmlNodeGetContent(node);
    if(s==NULL) return 0;
    if(xmlStrcmp(s,BAD_CAST value)==0)
        {
        result=1;
        }
    xmlFree(s);
    return result;
    }



